package com.wzk.travelspringboot.controller.admin;

import com.wzk.travelspringboot.dto.PageQuery;
import com.wzk.travelspringboot.dto.Result;
import com.wzk.travelspringboot.dto.ScenicDTO;
import com.wzk.travelspringboot.service.ScenicService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @author wangzikang
 */
@Slf4j
@RestController
@RequestMapping("/admin/scenic")
@RequiredArgsConstructor
@Validated
public class AdminScenicController {

    private final ScenicService scenicService;

    /**
     * 添加景区信息
     */
    @PostMapping("/put")
    public Result insertScenicData(@RequestBody @Valid ScenicDTO dto){
        return scenicService.insert(dto);
    }

    /**
     * 删除景区信息
     */
    @GetMapping("/remove/{id}")
    public Result deleteScenicData(@PathVariable(name = "id") @NotNull(message = "景区ID不能为空") Long id){
        boolean success = scenicService.removeById(id);
        return success ? Result.success("删除景区成功") : Result.failed("删除景区失败");
    }
    
    /**
     * 更新景区信息
     */
    @PostMapping("/update")
    public Result updateScenicData(@RequestBody @Valid ScenicDTO dto) {
        return scenicService.insert(dto);
    }
    
    /**
     * 分页查询所有景区信息
     */
    @GetMapping("/list")
    public Result listScenicData(PageQuery pageQuery) {
        return scenicService.queryAll(pageQuery);
    }
    
    /**
     * 根据ID查询景区详情
     */
    @GetMapping("/detail/{id}")
    public Result getScenicDetail(@PathVariable("id") @NotNull(message = "景区ID不能为空") Long id) {
        return scenicService.queryById(id);
    }
    
    /**
     * 根据名称模糊查询景区
     */
    @GetMapping("/search")
    public Result searchScenicByName(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam String name) {
        return scenicService.queryLikeName(pageNum, pageSize, name);
    }
}
